package view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
 * this class is Graphic user interface of Costumer Relation Employee, which extends AbstractGUI
 * @author jacob
 *
 */
public class CostumerRelEmpGui extends AbstractGUI {
/** all buttons of gui*/
	private JButton registerBut = null;
	private JButton backB = null;
	/** all Label of gui*/
	private JLabel lblUserName = null;
    private JLabel lblwarningMessage = null;
    private JLabel lbAge = null;
	private JLabel lblId = null;
	private JLabel lbphone = null;
	private JLabel lbArea = null;
	private JLabel lbLastName = null;
	private JLabel lbEmail = null;
	/** all TextField of gui*/
	private JTextField textFieldName = null;
	private JTextField textFieldId = null;
	private JTextField textFieldAge = null;
	private JTextField textFieldPhone = null;
	private JTextField textFieldLastName = null;
	private JTextField textFieldEmail = null;
	/**combo box of choose area*/
	private JComboBox AreaC;
	
	private Font myFont ;
/**
 * constructor 
 * this constructor add all the Label, Button,TextField on the Frame
 */
	public CostumerRelEmpGui(){
		
		 myFont = new Font("Serif",Font.BOLD,17);
		getContentPane().setLayout(null);
		getContentPane().add(getLblwarningMessage());
		getContentPane().add(getregisterBut());
		getContentPane().add(getlblUserName());
		getContentPane().add(getlblId());
		getContentPane().add(getlbAge());
		getContentPane().add(getlbphone());
		getContentPane().add(gettextFieldId());
		getContentPane().add(getTextFieldName());
		getContentPane().add(getTextFieldAge());
		getContentPane().add(getTextFieldPhone());
		getContentPane().add(getAreaC());
		getContentPane().add(getlbArea());
		getContentPane().add(getbackButton());
		getContentPane().add(getLbEmail());
		getContentPane().add(getLbLastName());
		getContentPane().add(getTextFieldEmail());
		getContentPane().add(getTextFieldLastName());
		
		getContentPane().setBackground(Color.orange);
		this.setTitle("ccrm/ Register costumer");
		this.setBounds(500, 200, 450, 470);
		
		//this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		this.setVisible(true);
		this.setResizable(false);
	}
	
	/*****************************************Getters and Setters of Labels, Buttons,TextFields,combo box *****************************/
	public JLabel getLblwarningMessage() {
		if(lblwarningMessage == null){
			lblwarningMessage = new JLabel("user name or password is wrong");
			lblwarningMessage.setForeground(Color.RED);
			lblwarningMessage.setBounds(10, 20, 200, 30);
			lblwarningMessage.setVisible(false);
		}
		return lblwarningMessage;
	}
	public void setWarningMessageVisibleTrue() {
		lblwarningMessage.setVisible(true);	
	}
	
	public void setWarningMessageVisibleTrue(String st) {
		lblwarningMessage.setText(st);
		lblwarningMessage.setForeground(Color.RED);
		lblwarningMessage.setBounds(40, 300, 245, 30);
		lblwarningMessage.setVisible(true);	
	}

	public JButton getregisterBut() {
		
		if(registerBut == null ) {
			registerBut = new JButton("Register");
			registerBut.setBounds(270, 350, 120, 20);
		}
		return registerBut;
	}
	
   public JButton getbackButton() {
		
		if(backB == null ) {
			backB = new JButton("back");
			backB.setBounds(80, 350, 120, 20);
		}
		return backB;
	}
	public JLabel getlblId() {
		if(lblId == null) {
			lblId = new JLabel("id:");
			lblId.setBounds(30, 70, 90, 20);
			lblId.setFont(myFont);
		}
		return lblId;
	}

	public JLabel getlblUserName() {
		if(lblUserName == null){
			lblUserName = new JLabel("Firts Name:");
			lblUserName.setBounds(30, 100, 120, 20);
			lblUserName.setFont(myFont);
		}
		return lblUserName;
	}
	public JLabel getlbAge() {
		if(lbAge == null){
			lbAge = new JLabel("Age:");
			lbAge.setBounds(30, 160, 90, 20);
			lbAge.setFont(myFont);
		}
		return lbAge;
	}
	public JLabel getlbphone() {
		if(lbphone == null){
			lbphone = new JLabel("phone :");
			lbphone.setBounds(30, 190, 90, 20);
			lbphone.setFont(myFont);
		}
		return lbphone;
	}
	
	public JLabel getlbArea() {
		if(lbArea == null){
			lbArea = new JLabel("Area :");
			lbArea.setBounds(30, 250, 90, 20);
			lbArea.setFont(myFont);
		}
		return lbArea;
	}
	
	public JTextField gettextFieldId() {
		if(textFieldId == null) {
			textFieldId = new JTextField();
			textFieldId.setBounds(120, 73, 130, 20);
			textFieldId.setColumns(10);
		}
		return textFieldId;
	}

	public JTextField getTextFieldName() {
		if(textFieldName == null) {
			textFieldName = new JTextField();
			textFieldName.setBounds(120, 103, 130, 20);
			textFieldName.setColumns(10);
		}
		return textFieldName;
	}
	
	public JTextField getTextFieldAge() {
		if(textFieldAge == null) {
			textFieldAge = new JTextField();
			textFieldAge.setBounds(120, 163, 130, 20);
			textFieldAge.setColumns(10);
		}
		return textFieldAge;
	}
	
	public JTextField getTextFieldPhone() {
		if(textFieldPhone == null) {
			textFieldPhone = new JTextField();
			textFieldPhone.setBounds(120, 193, 130, 20);
			textFieldPhone.setColumns(10);
		}
		return textFieldPhone;
	}

	public void ClearText(){
		textFieldPhone.setText("");
		textFieldAge.setText("");
		textFieldName.setText("");
		textFieldId.setText("");
		textFieldEmail.setText("");
		textFieldLastName.setText("");
	}
	public JLabel getLbLastName() {
		if(lbLastName == null) {
			lbLastName = new JLabel("Last Name:");
			lbLastName.setBounds(30, 130, 120, 20);
			lbLastName.setFont(myFont);
		}

		return lbLastName;
	}



	public JLabel getLbEmail() {
		if(lbEmail == null) {
			lbEmail = new JLabel("Email:");
			lbEmail.setBounds(30, 220, 90, 20);
			lbEmail.setFont(myFont);
		}
		return lbEmail;
	}



	public JTextField getTextFieldLastName() {
		if(textFieldLastName == null) {
			textFieldLastName = new JTextField();
			textFieldLastName.setBounds(120, 133, 130, 20);
			textFieldLastName.setColumns(10);
		}
		return textFieldLastName;
	}



	public JTextField getTextFieldEmail() {
		if(textFieldEmail == null) {
			textFieldEmail = new JTextField();
			textFieldEmail.setBounds(120, 223, 130, 20);
			textFieldEmail.setColumns(10);
		}
		return textFieldEmail;
	}
	/****************************************get the texts from Textfields******************************/
	public String getTextUserName() {
		return textFieldName.getText();
	}
	
	public String getTextphone() {
		
		return textFieldPhone.getText();
	}
	public String getTextId() {
		
		return textFieldId.getText();
	}
	
	public int getTextAge() {
		int foo;
		if(textFieldAge.getText().equals(""))
			return 0;
	try{
	   foo = Integer.parseInt(textFieldAge.getText()); 
	}
       catch(NumberFormatException e) { 
             return -1; 
      }
		return foo;
	}
	
	public String getTextAgeTe() {
		
		return textFieldAge.getText();
	}
	
	public String getTextEmail() {
		
		return textFieldEmail.getText();
	}
	public String getTextLastName() {
		
		return textFieldLastName.getText();
	}
	public JComboBox getAreaC() {
		if(AreaC == null){
			AreaC = new JComboBox();
			AreaC.setBounds(120, 253, 127, 20);
		}
		return AreaC;
	}




	public void setAreaC(JComboBox areaC) {
		AreaC = areaC;
	}
	
	public void undisplayWarningMessage() {
		lblwarningMessage.setVisible(false);
		
	}


	/********************************************add to all buttons ActionListener ************/
	public void addRegisterActionListener(ActionListener listener){
		registerBut.addActionListener(listener);
	}
	
	public void addAreaActionListener(ItemListener listener){
		AreaC.addItemListener(listener);
	}

	
	
	public void addbackBActionListener(ActionListener listener){
		backB.addActionListener(listener);
	}

}
